﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace UserSQLGenerator
{
    class DataGenerator
    {
        private const int NUM_STUDENTS_TO_GENERATE = 1000;
        private const int HNUMBER_SEED = 01600000;
        private const int START_YEAR = 2010;
        private const int CURRENT_YEAR = 2013;

        public static List<string>[] GenerateStudents()
        {
            List<string>[] list = new List<string>[8];
            list[0] = new List<string>();
            list[1] = new List<string>();
            list[2] = new List<string>();
            list[3] = new List<string>();
            list[4] = new List<string>();
            list[5] = new List<string>();
            list[6] = new List<string>();
            list[7] = new List<string>();

            //retrieve name arrays from text files
            string[] firstNames = System.IO.File.ReadAllLines("FirstNames.txt");
            string[] lastNames = System.IO.File.ReadAllLines("LastNames.txt");
            int firstNamesCount = firstNames.Count();
            int lastNamesCount = lastNames.Count();

            int hnumber = HNUMBER_SEED;
            int year = START_YEAR;
            Random random = new Random();

            for (int i = 0; i < NUM_STUDENTS_TO_GENERATE; i++)
            {

                list[0].Add("H" + hnumber);

                list[1].Add(random.Next(year, CURRENT_YEAR).ToString());

                list[2].Add(firstNames[random.Next(0, firstNamesCount)]);

                list[3].Add(lastNames[random.Next(0, lastNamesCount)]);

                list[4].Add(random.Next(year + 3, year + 5).ToString());

                if (random.Next(0, 50) == 0)
                    list[5].Add("Spring");
                else
                    list[5].Add("Fall");

                list[6].Add(year.ToString());

                if (random.Next(0, 100) == 0)
                    list[7].Add("Spring");
                else
                    list[7].Add("Fall");

                year = START_YEAR + (int)((double)i / (double)NUM_STUDENTS_TO_GENERATE * (double)(CURRENT_YEAR - START_YEAR));
                hnumber++;
            }


            return list;
        }
        public static List<string>[] GenerateStudentSubset(List<string>[] hnumbers, int percent)
        {
            List<string>[] list = new List<string>[1];
            list[0] = new List<string>();

            Random random = new Random();

            for (int i = 0; i < hnumbers[0].Count(); i++)
            {
                if (random.Next(0, 100) < percent) list[0].Add(hnumbers[0][i]);
            }


            return list;
        }
        public static List<string>[] GenerateTranscriptCourses(List<string>[] hnumbers)
        {
            List<string>[] list = new List<string>[4];
            list[0] = new List<string>();
            list[1] = new List<string>();
            list[2] = new List<string>();
            list[3] = new List<string>();

            //retrieve name arrays from text files
            string[] courses = System.IO.File.ReadAllLines("Courses.txt");
            int coursesCount = courses.Count();

            Random random = new Random();

            for (int i = 0; i < hnumbers[0].Count(); i++)
            {
                int numCourses;
                int chance = random.Next(0, 100);
                if (chance < 70)
                    numCourses = 1;
                else if (chance < 95)
                    numCourses = 2;
                else
                    numCourses = 3;

                for (int j = 0; j < numCourses; j++)
                {
                    list[0].Add(hnumbers[0][i]);

                    list[1].Add(courses[random.Next(0, coursesCount)]);

                    int grade = random.Next(0, 100);
                    if (grade < 2)
                        list[2].Add("I");
                    else if (grade < 10)
                        list[2].Add("F");
                    else if (grade < 15)
                        list[2].Add("D");
                    else if (grade < 65)
                        list[2].Add("C");
                    else if (grade < 90)
                        list[2].Add("B");
                    else
                        list[2].Add("A");

                    list[3].Add("3");
                }
            }


            return list;
        }
    }
}
